package cn.edu.glut.dto;

import javax.validation.constraints.NotNull;

import org.springframework.beans.BeanUtils;

import cn.edu.glut.entity.Major;
import cn.edu.glut.entity.Subject;
import cn.edu.glut.entity.Teacher;
import cn.edu.glut.utils.ValidValue;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
public class SubjectInputDTO implements DTOConvert<Subject>{
	
	private String id;		//该字段更新必传
	private String teacherId;	//新增必传
	@NotNull(message = ValidValue.Valid_MSG.SUBJECT_TITLE_NOT_NULL)
	private String title;
	@NotNull(message = ValidValue.Valid_MSG.SUBJECT_DESCRIPTION_NOTNULL)
	private String description;
	private Integer offer;	//供选人数，新增必传
	@NotNull(message = "题目所属专业不能为空")
	private String majorId;
	
	@Override
	public Subject convertToEntity() {
		Subject s = new Subject();
		BeanUtils.copyProperties(this, s);
		Teacher t = new Teacher(teacherId);
		Major m = new Major(majorId);
		s.setTeacher(t).setMajor(m);
		return s;
	}
}
